<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
<title>kq.1.06 ChatSocket</title>
<link rel="stylesheet" type="text/css" href="/Assets/app/library/static/main.css">
<script src="../kq.1.06.dev.js"></script>
<script src="/Assets/app/index.js"></script>
</head>

<body>
<div class="page page-fixed">
	<div class="page-foot pdl-15 pdr-15" style="position: absolute;left: 0;right: 0;bottom: 1rem;">
    	<div class="row-flex">
        	<div class="col-flex-other"><input id="sendInput" class="form-input" placeholder="请输入你的发言" /></div>
            <div class="col-flex-auto"><button id="sendBtn" class="wdr-4">发送</button></div>
        </div>
    </div>
</div>
</body>
<script>
var socket = new $Q.socket({
	addr:'127.0.0.1',//服务地址
	port:'51911',//端口信息
	//基础配置的数据信息，这个用于握手协议的内容信息
	config:{
		from_id:2,
		to_id:1
	},
	//这个是握手协议的返回信息
	success:function(rs){
		//todo--这里是握手协议成功之后的返回
		this.setParam('from_id',this.opts.config.from_id);
		this.setParam('to_id',this.opts.config.to_id);
		return true;
	},
});
socket.doMessage = function(rs){
	var data = $Q.jsonDecode(rs.data);
	if(data.is_send){
		//这个是接收信息的展示
		$Q.msg(data.message);
	}else{
		$Q.msg(data.message);
	}
}
$Q('#sendBtn').click(function(){
	var conts = $Q('#sendInput').val();
	if(!conts){
		return ;	
	}	
	socket.doSend({conts:conts});
	$Q('#sendInput').val("");
});
console.log(socket);
</script>
</html>
